﻿using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using BSU.GraduateWork.Data.Model;
using BSU.GraduateWork.Data.Repositories.Interfaces;

namespace BSU.GraduateWork.Data.Repositories
{
    public class ProblemRepository : BaseRepository<Problem, int>, IProblemRepository
    {
        #region IProblemRepository Members

        

        #endregion

        public override Problem Get(int id)
        {
            return base.Get(id);
        }

        public override Problem Save(Problem entity)
        {
            var dlo = new DataLoadOptions();
            //dlo.LoadWith<Solution>(s => s.Points);
            
            var context = GetNewContext();
            //context.GetTable<InputParameters>().Attach(entity.InputParameters);
            
            //context.GetTable<Point>().AttachAll(entity.Solution.Points);
            entity = base.Save(entity, context);

            foreach (var point in entity.Solution.Points)
            {
                point.SolutionId = entity.SolutionId;
                PointRepository rep = new PointRepository();
                rep.Save(point);
            }
            
            return entity;
        }
    }
}